USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[sysdiagrams-Insert]    Script Date: [[20120731133241]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120731133241]]
-- Description:	Insert record into table [dbo].[sysdiagrams]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[sysdiagrams-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[sysdiagrams-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[sysdiagrams-Insert]
	/*@name nvarchar(128) =Null  , 
	@principal_id int =Null  , 
	@diagram_id int =Null OUTPUT , 
	@version int =Null  , 
	@definition varbinary =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[sysdiagrams](/*[name], [principal_id], [version], [definition]*/)
	VALUES     (/*@name, @principal_id, @version, @definition*/)

	/*SELECT @diagram_id = [diagram_id]
    FROM [dbo].[sysdiagrams]
    WHERE  ( [name] =@name )
	AND  ( [principal_id] =@principal_id )
	AND  ( [version] =@version )
	AND  ( [definition] =@definition )*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[sysdiagrams-update]    Script Date: [[20120731133241]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120731133241]]
-- Description:	Update record in table [dbo].[sysdiagrams]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[sysdiagrams-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[sysdiagrams-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[sysdiagrams-update]
	/*@name nvarchar(128) =Null  , 
	@principal_id int =Null  , 
	@diagram_id int =Null OUTPUT , 
	@version int =Null  , 
	@definition varbinary =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/**/
		Update [dbo].[sysdiagrams] SET 
		/*[name] =@name, 
		[principal_id] =@principal_id, 
		[version] =@version, 
		[definition] =@definition*/
		/*WHERE ([diagram_id] = @diagram_id)*/
	/**/

	/*SELECT @diagram_id = [diagram_id]
    FROM [dbo].[sysdiagrams]
	WHERE ([diagram_id] = @diagram_id)*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[sysdiagrams-Insert-Update]    Script Date: [[20120731133241]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120731133241]]
-- Description:	Insert OR Update record into table [dbo].[sysdiagrams]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[sysdiagrams-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[sysdiagrams-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[sysdiagrams-Insert-Update]
	/*@name nvarchar(128) =Null  , 
	@principal_id int =Null  , 
	@diagram_id int =Null OUTPUT , 
	@version int =Null  , 
	@definition varbinary =Null  , 
	@Inserted bit OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[sysdiagrams] 
					/*WHERE ([diagram_id] = @diagram_id)*/)
	BEGIN
		
		INSERT  INTO [dbo].[sysdiagrams](/*[name], [principal_id], [version], [definition]*/)
		VALUES     (/*@name, @principal_id, @version, @definition*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/**/
			Update [dbo].[sysdiagrams] SET 
			/*[name] =@name, 
			[principal_id] =@principal_id, 
			[version] =@version, 
			[definition] =@definition*/
			/*WHERE ([diagram_id] = @diagram_id)*/
		/**/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @diagram_id = [diagram_id]
    FROM [dbo].[sysdiagrams]
	WHERE ([diagram_id] = @diagram_id)*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[sysdiagrams-Delete]    Script Date: [[20120731133241]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120731133241]]
-- Description:	delete records from table [dbo].[sysdiagrams] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[sysdiagrams-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[sysdiagrams-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[sysdiagrams-Delete]
	/*@name nvarchar(128) =null  , 
	@principal_id int =null  , 
	@diagram_id int =null  , 
	@version int =null  , 
	@definition varbinary =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[sysdiagrams]
	WHERE /*( [name] like ISNULL(@name, [name]) )
	AND ( [principal_id] = ISNULL(@principal_id, [principal_id]) )
	AND ( [diagram_id] = ISNULL(@diagram_id, [diagram_id]) )
	AND ( [version] = ISNULL(@version, [version]) )
	AND ( [definition] = ISNULL(@definition, [definition]) )*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[sysdiagrams-Select]    Script Date: [[20120731133241]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120731133241]]
-- Description:	select records from table [dbo].[sysdiagrams] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[sysdiagrams-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[sysdiagrams-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[sysdiagrams-Select]
	/*@name nvarchar(128) =null  , 
	@principal_id int =null  , 
	@diagram_id int =null  , 
	@version int =null  , 
	@definition varbinary =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[sysdiagrams]
	WHERE /*( [name] like ISNULL(@name, [name]) )
	AND ( [principal_id] = ISNULL(@principal_id, [principal_id]) )
	AND ( [diagram_id] = ISNULL(@diagram_id, [diagram_id]) )
	AND ( [version] = ISNULL(@version, [version]) )
	AND ( [definition] = ISNULL(@definition, [definition]) )*/
END
GO
-- =============================================
